/**
 * SKObject.h
 * Coyright (c) 2009 Xiaofeng Gu. All Rights Reserved.
 * Author : Xiaofeng Gu
 *
 * Creation Data : 2009/07/14
 */

#pragma once

#include "IGraphics.h"
#include "IPersistence.h"

class CSKObject : public IGraphics, public IPersistence
{
public:
	enum SKObjectType
	{
		eNone = -1,
		eNode,
		eKnot,
		eFamily,
		eTimeline
	};

	CSKObject()
		: m_bVisibility(true),
		  m_hTreeItem(NULL),
		  m_bActive(false),
		  m_bExpanded(false)
	{
	}
	virtual ~CSKObject()
	{
	}

	virtual SKObjectType		GetSKObjectType() = 0;

public:
	virtual bool				OnRead(CXMLParser* pParser) { return true; }
	virtual bool				OnWrite(CXMLParser* pParser) { return true; }

public:
	virtual void			Render() = 0;
	virtual CGBox&			GetRangeBox()
	{ return m_oRangeBox; }
	virtual void			Visibility(bool bVisibility)
	{ m_bVisibility = bVisibility; }
	virtual bool			IsVisibility()
	{ return m_bVisibility; }

	void					SetTreeItem(HTREEITEM item) { m_hTreeItem = item; }
	HTREEITEM				GetTreeItem() { return m_hTreeItem; }

	virtual void			SetActive(bool bActive)
	{ m_bActive = bActive; }
	bool					GetActive()
	{ return m_bActive; }

	bool					IsExpand() { return m_bExpanded; }
	virtual void			UpdateExpandStatus(CTreeCtrl* pTree);
	virtual void			Expand(CTreeCtrl* pTree);

	virtual CString			GetName() = 0;

	virtual void Back() {}
	virtual void Rollback() {}

protected:
	bool			m_bVisibility;
	CGBox			m_oRangeBox;
	HTREEITEM		m_hTreeItem;
	bool			m_bActive;
	bool			m_bExpanded;
};

inline void CSKObject::UpdateExpandStatus(CTreeCtrl* pTree)
{
	m_bExpanded = (pTree->GetItemState(m_hTreeItem, TVIS_EXPANDED) & TVIS_EXPANDED) != 0;
}

inline void CSKObject::Expand(CTreeCtrl* pTree)
{
	pTree->Expand(m_hTreeItem, IsExpand() ? TVE_EXPAND : TVE_COLLAPSE);
}